<!-- 通知详情 -->
<script setup lang="ts">
import MpHtml from 'mp-html/src/uni-app/components/mp-html/mp-html.vue'
import { fetchNoticeDetailAPI } from '@/apis/fetchNoticeDetail'
import { useUserInfoStore } from '@/store/userInfo'

const userInfoStore = useUserInfoStore()

// 通知详情数据
const notice = ref<NoticeDetail | null>(null)
// 是否处于加载中状态
const loading = ref(false)

onLoad(async (options) => {
  if (options && options.id) {
    try {
      loading.value = true
      const res = await fetchNoticeDetailAPI(options.id, userInfoStore.userInfo!.token!)
      loading.value = false
      if (res.data?.code === 1)
        notice.value = res.data?.data
      else
        uni.showToast({ title: res.data?.msg, icon: 'none' })
    }
    catch (err) {
      uni.showToast({ title: JSON.stringify(err) })
    }
  }
})
</script>

<template>
  <view class="px-40rpx">
    <Spacer height="40" />
    <view class="text-44rpx font-semibold leading-60rpx">
      {{ notice?.title || '未知标题' }}
    </view>
    <Spacer height="12" />
    <view class="text-28rpx leading-40rpx">
      发布时间：{{ notice?.create_time || '未知时间' }}
    </view>
    <Spacer height="32" />
    <Divider width="671" color="#E6E6E6" />
    <Spacer height="32" />
    <MpHtml :content="notice?.content || '未知内容'" />
  </view>
  <uv-loading-page :loading="loading" loading-text="加载中..." font-size="28rpx" loading-mode="spinner" />
</template>

<route lang="yaml">
name: 'noticeDetail'
style:
  navigationBarTitleText: '通知'
layout: 'custom'
</route>
